Face-detecting

Detecting face from photo or camera


Setup

pip install -r requirements.txt


Usage

python3 main.py detecting face from camera q for exit from frame

pyhton3 detect_face_from_image detecting face from images on directory images q for exit from frame

Source Code: main.py

# обнаруживает пока что только лицо и пишет на рамочке

import cv2

video = cv2.VideoCapture(0)
hands_hear_cascade = cv2.CascadeClassifier('Cascade-Files/more_bet.xml')

# Write some Text

font = cv2.FONT_ITALIC
text = 'Face detected'
fontScale = 1
fontColor = (0, 255, 0)
thickness = 3
lineType = 1

while True:
    _r, frame = video.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    hands = hands_hear_cascade.detectMultiScale(gray, 1.1, 3)

    if len(hands):
        print("Face")

        for x, y, w, h in hands:
            bottomLeftCornerOfText = (x - 5, y - 5)
            cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
            cv2.putText(frame, text,
                        bottomLeftCornerOfText,
                        font,
                        fontScale,
                        fontColor,
                        thickness,
                        lineType)
    cv2.imshow("test", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
video.release()
cv2.destroyAllWindows()